package com.lz.ovuola.util.redis.single;

import java.io.Serializable;

import javax.annotation.Resource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import com.lz.ovuola.util.redis.cluster.HessianSerializer;

@Configuration
public class CustomSingleRedisTemplate {
	@Resource(name = "redisSingleConnectionFactory")
	private RedisConnectionFactory redisSingleConnectionFactory;
	@Resource
	private HessianSerializer hessianSerializer;

	@Bean("redisTemplate")
	public RedisTemplate<String, Serializable> redisTemplate() {
		RedisTemplate<String, Serializable> redisTemplate = new RedisTemplate<String, Serializable>();
		redisTemplate.setConnectionFactory(redisSingleConnectionFactory);
		redisTemplate.setKeySerializer(new StringRedisSerializer());
		// redisTemplate.setValueSerializer(hessianSerializer);
		redisTemplate.setHashKeySerializer(hessianSerializer); // 最好也使用默认
		redisTemplate.setHashValueSerializer(hessianSerializer);
		return redisTemplate;
	}
}